package com.webshop.service;

import com.webshop.DataDao.UserDataBase;
import com.webshop.JavaBean.User;

public class UserService  {
    private UserDataBase cd = new UserDataBase();

    /**
     * 判断电话是否已存在
     * @param phone
     * @return
     */
    public boolean isHavaPhone(String phone)
    {
           return cd.isHavePhone(phone);
    }

    /**
     * 判断邮箱是否已存在
     * @param Email
     * @return
     */
    public boolean isHavaEmail(String Email)
    {
        return cd.isHaveEmail(Email);
    }

    /**
     * 判断用户名是否已存在
     * @param name
     * @return
     */
    public boolean isHavaName(String name)
    {
        return cd.isHaveName(name);
    }

    /**
     * 保存用户信息
     * @param user
     * @return
     */
    public boolean savedUser (User user)
    {
        try {
            if(!isHavaName(user.getName()))
            {
                cd.insertUser(user);
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }

    /**
     * 验证登录
     * @param name
     * @param password
     * @return
     */
    public boolean login(String name,String password)
    {
        return cd.login(name,password);
    }


    /**
     * 获取用户信息
     * @param name
     * @return
     */
    public User getUserInfo(String name)
    {
        User temp = cd.getUser(name);
        return temp;
    }

    /**
     * 修改密码时，验证用户邮箱
     * @param name
     * @param email
     * @return
     */
    public boolean justifyEmail (String name, String email) {
        boolean flag = cd.justifyEmail(name, email);
        if (flag) {

            return true;
        }
        return false;
    }

    /**
     * 正式的修改密码的方法
     * @param name
     * @param password
     */
    public void changePassword(String name, String password) {
        cd.changePassword(name, password);

    }

    /**
     * 修改个人中心用的查找
     * @param name
     * @return
     * @throws Exception
     */
    public User usermodify(String name)throws Exception{
        User user=new User();
        user=cd.usermodify(name);
        return user;
    }

    /**
     * 修改信息
     * @param phone
     * @param email
     * @param name
     * @throws Exception
     */
    public void updataper(String phone,String email,String name)throws Exception{
        cd.updateper(phone,email,name);
    }
}
